from appium import webdriver
from app_study.app_snowball.base.base_page import BasePage


# app 的相关操作：雪球start启动、重启restart、停止 stop
class SnowballApp(BasePage):
    def start(self):
        # 启动app
        if self.driver == None:
            print("driver == None")
            desired_caps = {}
            # Android 包名和页面名，获取命令：
            # mac/linux: adb logcat ActivityManager:I | grep "cmp"
            # windows: adb logcat ActivityManager:I | findstr "cmp"
            desired_caps["platformName"] = "Android"
            desired_caps["platformVersion"] = "7.1.2"
            desired_caps["deviceName"] = "attached-5554"
            desired_caps["appPackage"] = "com.xueqiu.android"
            desired_caps["appActivity"] = ".view.WelcomeActivityAlias"
            desired_caps["noReset"] = "true"
            self.driver = webdriver.Remote("http://localhost:4723/wd/hub", desired_caps)
            self.driver.implicitly_wait(10)
        else:
            # 直接启动APP
            print("复用driver")
            self.driver.launch_app()
        return self

    def restart(self):
        pass

    def stop(self):
        self.driver.quit()

    # 切换到配置中完成po操作
    def goto_main(self):
        from app_study.app_snowball.page.main_page import MainPage
        return MainPage(self.driver)